// WndMenuButton.cpp : implementation file
//

#include "stdafx.h"
#include "BBViewer.h"
#include "WndMenuButton.h"


// CWndMenuButton

IMPLEMENT_DYNAMIC(CWndMenuButton, CWnd)

CWndMenuButton::CWndMenuButton()
{
}

CWndMenuButton::~CWndMenuButton()
{
}


BEGIN_MESSAGE_MAP(CWndMenuButton, CWnd)
	ON_WM_CREATE()
	ON_WM_SIZE()
	ON_MESSAGE(WM_CTL_MESSAGE, OnCtlMessage)
END_MESSAGE_MAP()



// CWndMenuButton message handlers



int CWndMenuButton::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CWnd::OnCreate(lpCreateStruct) == -1)
		return -1;

	int i;
	LPST_BMP_INFO lpBmpInfo;
	for (i=0;i<4;i++)
	{
		lpBmpInfo = theApp.BmpInfo.GetAt(biPrint_normal+i);
		m_btnPrint.SetBitmaps(i, lpBmpInfo->hbmpImage);

		lpBmpInfo = theApp.BmpInfo.GetAt(biSetup_normal+i);
		m_btnSetup.SetBitmaps(i, lpBmpInfo->hbmpImage);

		lpBmpInfo = theApp.BmpInfo.GetAt(biBackup_normal+i);
		m_btnRecord.SetBitmaps(i, lpBmpInfo->hbmpImage);

		lpBmpInfo = theApp.BmpInfo.GetAt(biViewer_normal+i);
		m_btnInfo.SetBitmaps(i, lpBmpInfo->hbmpImage);

		lpBmpInfo = theApp.BmpInfo.GetAt(biMenuOpen_normal+i);
		m_btnOpen.SetBitmaps(i, lpBmpInfo->hbmpImage);

		lpBmpInfo = theApp.BmpInfo.GetAt(biMenuDel_normal+i);
		m_btnDelete.SetBitmaps(i, lpBmpInfo->hbmpImage);
	}

	int nBtnCount = 0;

	CCtrlButton *pBtn[6];
	pBtn[nBtnCount++] = &m_btnPrint;
	pBtn[nBtnCount++] = &m_btnSetup;
	pBtn[nBtnCount++] = &m_btnRecord;
	pBtn[nBtnCount++] = &m_btnInfo;
	pBtn[nBtnCount++] = &m_btnOpen;
	pBtn[nBtnCount++] = &m_btnDelete;

	for (i=0;i<nBtnCount;i++)
	{
		lpBmpInfo = theApp.BmpInfo.GetAt(biPrint_normal+(i*4));
		if (!pBtn[i]->Create(NULL, NULL, WS_CHILD|WS_VISIBLE, CRect(0,0,0,0), this, lpBmpInfo->uImageID, NULL))
			return -1;
	}

	LoadText();

	m_ToolTipCtrl.Create(this);
	m_ToolTipCtrl.Activate(TRUE);

	for (i=0;i<nBtnCount;i++)
		m_ToolTipCtrl.AddTool(pBtn[i], m_sarrText.GetAt(i));

	return 0;
}

void CWndMenuButton::OnSize(UINT nType, int cx, int cy)
{
	CWnd::OnSize(nType, cx, cy);

	LPST_WND_POS lpWndPos;
	lpWndPos = theApp.WndPos.GetAt(wpMenu_print);
	theApp.SetWindowPosition(&m_btnPrint, cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo);
	lpWndPos = theApp.WndPos.GetAt(wpMenu_setup);
	theApp.SetWindowPosition(&m_btnSetup, cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo);
	lpWndPos = theApp.WndPos.GetAt(wpMenu_backup);
	theApp.SetWindowPosition(&m_btnRecord, cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo);
	lpWndPos = theApp.WndPos.GetAt(wpMenu_info);
	theApp.SetWindowPosition(&m_btnInfo, cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo);
	lpWndPos = theApp.WndPos.GetAt(wpMenu_open);
	theApp.SetWindowPosition(&m_btnOpen, cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo);
	lpWndPos = theApp.WndPos.GetAt(wpMenu_delete);
	theApp.SetWindowPosition(&m_btnDelete, cx, cy, lpWndPos->rtWndPos, lpWndPos->rtStickTo);
}

BOOL CWndMenuButton::PreTranslateMessage(MSG* pMsg)
{
	m_ToolTipCtrl.RelayEvent(pMsg);
	return CWnd::PreTranslateMessage(pMsg);
}

long CWndMenuButton::OnCtlMessage(UINT wParam, LONG lParam)
{
	CWnd* pParent = GetParent();
	pParent->PostMessage(WM_CTL_MESSAGE, wParam, lParam);
	return 0;
}

void CWndMenuButton::SetPrintButtonStatus(BOOL bEnable)
{
	m_btnPrint.EnableWindow(bEnable);
}

void CWndMenuButton::SetBackupButtonStatus(BOOL bEnable)
{
	m_btnRecord.EnableWindow(bEnable);
}

void CWndMenuButton::SetDeleteButtonStatus(BOOL bEnable)
{
	m_btnDelete.EnableWindow(bEnable);
}

void CWndMenuButton::RefreshLang()
{
	LoadText();

	CCtrlButton *pBtn[6];
	int nBtnCount = 0;
	int i;
	pBtn[nBtnCount++] = &m_btnPrint;
	pBtn[nBtnCount++] = &m_btnSetup;
	pBtn[nBtnCount++] = &m_btnRecord;
	pBtn[nBtnCount++] = &m_btnInfo;
	pBtn[nBtnCount++] = &m_btnOpen;
	pBtn[nBtnCount++] = &m_btnDelete;

	for (i=0;i<nBtnCount;i++)
	{
		m_ToolTipCtrl.DelTool(pBtn[i]);
		m_ToolTipCtrl.AddTool(pBtn[i], m_sarrText.GetAt(i));
	}

}

void CWndMenuButton::LoadText()
{
	m_sarrText.RemoveAll();

	m_sarrText.Add(theApp.GetUIString(APPNAME_BUTTON, KEYNAME_BUTTON_PRINT, KEYNAME_BUTTON_PRINT));
	m_sarrText.Add(theApp.GetUIString(APPNAME_BUTTON, KEYNAME_BUTTON_SETUP, KEYNAME_BUTTON_SETUP));
	m_sarrText.Add(theApp.GetUIString(APPNAME_BUTTON, KEYNAME_BUTTON_BACKUP, KEYNAME_BUTTON_BACKUP));
	m_sarrText.Add(theApp.GetUIString(APPNAME_BUTTON, KEYNAME_BUTTON_VIEWER_SETTING, KEYNAME_BUTTON_VIEWER_SETTING));
	m_sarrText.Add(theApp.GetUIString(APPNAME_BUTTON, KEYNAME_BUTTON_FILEOPEN, KEYNAME_BUTTON_FILEOPEN));
	m_sarrText.Add(theApp.GetUIString(APPNAME_BUTTON, KEYNAME_BUTTON_DELETE, KEYNAME_BUTTON_DELETE));

}